package com.viser.partyinrs.entities;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MestoKomentar implements Serializable, Comparable<MestoKomentar> {
	private static final long serialVersionUID = 1000005L;
	
	public String username = "";  // Username korisnika koji je ostavio komentar
	public int idMesto = 0;
	public String tekst = "";
	public int ocena = 0;
	public String datumVreme = "";  // "yyyy/MM/dd HH:mm:ss" <-- mora ovako!
	
	public MestoKomentar()
	{
		super();
	}

	public MestoKomentar(String username, int idMesto, String tekst, int ocena, String datumVreme) {
		super();
		this.username = username;
		this.idMesto = idMesto;
		this.tekst = tekst;
		this.ocena = ocena;
		this.datumVreme = datumVreme;
	}

	@Override
	public int compareTo(MestoKomentar drugi) {
		Date ovoVreme = new Date();
		SimpleDateFormat sdf1 = new SimpleDateFormat();
		sdf1.applyPattern("yyyy/MM/dd HH:mm:ss");
		try {
			ovoVreme = sdf1.parse(this.datumVreme);
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		
		Date drugoVreme = new Date();
		SimpleDateFormat sdf2 = new SimpleDateFormat();
		sdf2.applyPattern("yyyy/MM/dd HH:mm:ss");
		try {
			drugoVreme = sdf2.parse(drugi.datumVreme);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return ovoVreme.compareTo(drugoVreme);
	}
}
